home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / snpd1292.zip / EXT_KEYS.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  1KB  |  57 lines

  1. /*
  2. **  ext_getch()
  3. **
  4. **  A getch() work-alike for use with extended keyboards.
  5. **
  6. **  Parameters: none
  7. **
  8. **  Returns: Extended key code as follows:
  9. **           0->255     Normal key
  10. **           256->511   Numeric pad key or Function key
  11. **           512->767   Cursor pad key or Numeric pad
  12. **                      "duplicate" key (Enter, /, *, -, +)
  13. **
  14. **  Original Copyright 1992 by Bob Stout as part of
  15. **  the MicroFirm Function Library (MFL)
  16. **
  17. **  This subset version is hereby donated to the public domain.
  18. */
  19.  
  20. #include <dos.h>
  21. #include <ctype.h>
  22.  
  23. #define LoByte(x) ((unsigned char)((x) & 0xff))
  24. #define HiByte(x) ((unsigned char)((unsigned short)(x) >> 8))
  25.  
  26. int ext_getch(void)
  27. {
  28.       int key;
  29.       union REGS regs;
  30.  
  31.       regs.h.ah = 0x10;
  32.       int86(0x16, ®s, ®s);
  33.       key = regs.x.ax;
  34.  
  35.       switch (LoByte(key))
  36.       {
  37.       case 0:
  38.             key = HiByte(key) + 256;
  39.             break;
  40.  
  41.       case 0xe0:
  42.             key = HiByte(key) + 512;
  43.             break;
  44.  
  45.       default:
  46.             if (0xe0 == HiByte(key))
  47.                   key = LoByte(key) + 512;
  48.             else
  49.             {
  50.                   if (ispunct(LoByte(key)) && HiByte(key) > 0x36)
  51.                         key = LoByte(key) + 512;
  52.                   else  key = LoByte(key);
  53.             }
  54.       }
  55.       return key;
  56. }
  57.